package com.example.demo.controller;

import com.example.demo.pojo.Emp;
import com.example.demo.pojo.EmpQueryParam;
import com.example.demo.pojo.PageResult;
import com.example.demo.pojo.Result;
import com.example.demo.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

@RequestMapping("/emps")
@Slf4j
@RestController
public class EmpController {

    @Autowired
    private EmpService empService;

    @GetMapping
    public Result page(EmpQueryParam empQueryParam){
       log.info("查询请求参数： {}", empQueryParam);
        PageResult pageResult = empService.page(empQueryParam);
        return Result.success(pageResult);
    }
    @PostMapping
    public Result save(@RequestBody Emp emp) throws Exception {

        log.info("请求参数emp: {}", emp);
    empService.save(emp);
    return Result.success();
}

    /**
     * 批量删除员工
     */
    /**
     * 批量删除员工
     */
//    @DeleteMapping
//    public Result delete(@RequestParam List<Integer> ids){
//        log.info("批量删除部门: ids={} ", ids);
//        empService.deleteByIds(ids);
//        return Result.success();
//    }
      @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids)
      {
          log.info("批量删除部门: ids={}",ids);
          empService.deleteByIds(ids);

          return Result.success();
      }
      @PutMapping()
    public Result update(@RequestBody  Emp emp){

          log.info("修改员工信息{}",emp);

             empService.update(emp);

            return Result.success(emp);

      }


      @GetMapping("/list")
    public  Result list(){

        List  <Emp> e  = empService.all();

          return Result.success(e);
      }

}

